﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package net.wooga.pets.models.world.vos.actors {
    import flash.events.*;
    import flash.geom.*;
    import net.wooga.pets.events.*;
    import net.wooga.pets.interfaces.*;
    import net.wooga.pets.constants.*;

    public class DoctorVO extends AbstractActorVO implements IEating, ITreating, ITicking {

        private var _hungryAt:int;
        private var _hungryIn:int;// = 0
        private var _isHungry:Boolean;
        private var _time:int;
        private var _animationState:String;// = "still"
        private var _pendingFoodCalls:int;

        private static var _canEat:Boolean = false;

        public function DoctorVO(_arg1:Object, _arg2:IEventDispatcher){
            super(_arg1, _arg2);
            this.eat(_arg1[ProtocolConstants.HUNGRY_AT]);
            speechBubblePosition = new Point(30, -200);
            dispatch(new TickingEvent(TickingEvent.ADD_TICKING, this, TimeConstants.SECOND));
        }
        public function eat(_arg1:int):void{
            this._hungryAt = _arg1;
            removeSpeechBubble();
            this.checkHunger();
        }
        public function get hungryAt():int{
            return (this._hungryAt);
        }
        public function set hungryAt(_arg1:int):void{
            this._hungryAt = _arg1;
        }
        public function get hungryIn():int{
            return (this._hungryIn);
        }
        public function get canEat():Boolean{
            return (_canEat);
        }
        public function get isHungry():Boolean{
            return (((_canEat) && (this._isHungry)));
        }
        public function set pendingCoffee(_arg1:int):void{
            this._pendingFoodCalls = _arg1;
        }
        public function get pendingCoffee():int{
            return (this._pendingFoodCalls);
        }
        public function get isTreating():Boolean{
            return (((!(this.isHungry)) && (this._time)));
        }
        override public function set animationState(_arg1:String):void{
            this._animationState = _arg1;
            dispatch(new InfoEvent(EventConstants.SET_ANIMATION_STATE, id, this._animationState));
        }
        override public function get animationState():String{
            return (this._animationState);
        }
        public function onTick(_arg1:Boolean=true, _arg2:Number=0):void{
            this._time = _arg2;
            this.checkHunger();
        }
        override public function destroy():void{
            super.destroy();
            dispatch(new TickingEvent(TickingEvent.REMOVE_TICKING, this));
        }
        private function checkHunger():void{
            if (((_canEat) && (this._time))){
                this._hungryIn = (this._hungryAt - this._time);
                if (((!(this._isHungry)) && ((this._hungryIn < 0)))){
                    this._isHungry = true;
                    dispatch(new InfoEvent(EventConstants.ON_DOCTOR_HUNGRY, id, this));
                    this.animationState = GameConstants.ANIMATION_STATE_SLEEP;
                    dispatch(new InfoEvent(EventConstants.ENABLE_DARKEN_ROOM, roomId));
                    showSpeechBubble(SpeechBubbleConstants.TYPE_ICON_BUBBLE, {icon:SpeechBubbleConstants.ICON_HUNGRY});
                } else {
                    if (((this._isHungry) && ((this._hungryIn > 0)))){
                        this._isHungry = false;
                        dispatch(new InfoEvent(EventConstants.ON_DOCTOR_HAS_EATEN, id, this));
                        this.animationState = GameConstants.ANIMATION_STATE_WAKE;
                        dispatch(new InfoEvent(EventConstants.DISABLE_DARKEN_ROOM, roomId));
                    } else {
                        if (((this._isHungry) && (!((this.animationState == GameConstants.ANIMATION_STATE_SLEEP))))){
                            this.animationState = GameConstants.ANIMATION_STATE_SLEEP;
                        };
                    };
                };
            };
        }

        public static function set canEat(_arg1:Boolean):void{
            _canEat = _arg1;
        }

    }
}//package net.wooga.pets.models.world.vos.actors 
